<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    
</body>
<script>
    //99.40%
    var romanToInt = function(s) {
        const roma = {
            I: 1,
            V: 5,
            X: 10,
            L: 50,
            C: 100,
            D: 500,
            M: 1000,
        }
        return s.split('').reduce((pre, cur, ind, arr)=>{
            if(roma[cur] < roma[arr[ind+1]]){
                pre -= roma[cur];
            }else{
                pre += roma[cur];
            }
            return pre;
        },0)
    };
    let s = "MCMXCIV";
    console.log(romanToInt(s));
    
</script>
</html>